package com.yiwei.zxp.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.SearchResultActivity;
import com.yiwei.zxp.util.UI;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class SearchHistoryAdapter extends ItemAdapter<String, SearchHistoryAdapter.DefaultHolder> {


    private Context context;

    public SearchHistoryAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_search_history, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        holder.txtSearch.setText(getItem(position));
        holder.txtSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, SearchResultActivity.class);
                intent.putExtra("keyword", UI.toString(holder.txtSearch));
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_search)
        TextView txtSearch;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
